<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/welcome' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <el-row>
        <el-col :span="8">
          <el-input placeholder="请输入内容" v-model="queryInfo.query" clearable>
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
      </el-row>

      <el-table :data="ordersList" border style="width: 100%" stripe>
        <el-table-column type="index"></el-table-column>
        <el-table-column prop="order_number" label="订单编号" width="500"></el-table-column>
        <el-table-column prop="order_price" label="订单价格"></el-table-column>
        <el-table-column prop="order_pay" label="是否付款">
          <template slot-scope="scope">
            <el-tag type="success" v-if="scope.row.order_pay==1">已付款</el-tag>
            <el-tag type="danger" v-else>未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货"></el-table-column>
        <el-table-column prop="create_time" label="下单时间" width="200">
          <template slot-scope="scope">{{scope.row.create_time|dateFormate}}</template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
              type="primary"
              size="mini"
              icon="el-icon-edit"
              @click="editDialogVisible=true"
            ></el-button>
            <el-button type="success" size="mini" icon="el-icon-setting" @click="getProgress"></el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[7, 10, 15]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
      <el-dialog title="修改地址" :visible.sync="editDialogVisible" width="50%" @close="dialogClose">
        <el-form :model="orderForm" :rules="orderRules" ref="addressFormRef" label-width="100px">
          <el-form-item label="省市区/县" prop="order_p">
            <el-cascader v-model="orderForm.address_p" :options="cityData" class="cascader_p"></el-cascader>
          </el-form-item>
          <el-form-item label="详细地址" prop="order_address">
            <el-input v-model="orderForm.address"></el-input>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="editDialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="editDialogVisible = false">确 定</el-button>
        </span>
      </el-dialog>

      <el-dialog title="物流信息" :visible.sync="waterDialogVisible" width="50%">
        <el-timeline>
          <el-timeline-item
            v-for="(activity, index) in progressData"
            :key="index"
            :timestamp="activity.time"
          >{{activity.context}}</el-timeline-item>
        </el-timeline>
      </el-dialog>
    </el-card>
  </div>
</template>

<script>
import cityData from "./citydata.js";
export default {
  data() {
    return {
      queryInfo: {
        query: "",
        pagenum: 1,
        pagesize: 7
      },
      ordersList: [],
      total: 0,
      orderForm: {
        address_p: [],
        address: ""
      },
      orderRules: {
        order_p: [
          { required: true, message: "请输入省市区/县", trigger: "blur" }
        ],
        order_address: [
          { required: true, message: "请输入详细地址", trigger: "blur" }
        ]
      },
      cityData,
      editDialogVisible: false,
      waterDialogVisible: false,
      progressData: []
    };
  },
  created() {
    this.getOrdersList();
  },
  methods: {
    async getOrdersList() {
      const { data: res } = await this.$http.get("orders", {
        params: this.queryInfo
      });
      if (res.meta.status != 200) {
        this.$message.error("获取订单列表失败");
      }
      this.ordersList = res.data.goods;
      this.total = res.data.total;
    },
    handleSizeChange(val) {
      this.queryInfo.pagesize = val;
      this.getOrdersList();
    },
    handleCurrentChange(val) {
      this.queryInfo.pagenum = val;
      this.getOrdersList();
    },
    dialogClose() {
      this.$refs.addressFormRef.resetFields();
    },
    async getProgress() {
      const { data: res } = await this.$http.get("/kuaidi/1106975712662");
      if (res.meta.status != 200) {
        this.$message.error("获取物流信息失败");
      }
      this.progressData = res.data;
      this.waterDialogVisible = true;
    }
  }
};
</script>

<style lang="less" scoped>
.cascader_p {
  width: 100%;
}
</style>